package com.android.pocketguru;

import com.android.pocketguru.Fragments.DialogPopupFragment;
import com.android.pocketguru.Fragments.PopupFragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.view.WindowManager.LayoutParams;

public class PopupActivity extends FragmentActivity {

	
	//@Override
	protected void onCreate(Bundle savedInstanceState) {		
		super.onCreate(savedInstanceState);	
		
		//getWindow().addFlags(LayoutParams.FLAG_TURN_SCREEN_ON | LayoutParams.FLAG_DISMISS_KEYGUARD);
		getWindow().addFlags(LayoutParams.FLAG_TURN_SCREEN_ON | LayoutParams.FLAG_SHOW_WHEN_LOCKED);
		
		// For test purposes. Or maybe later for windowed pop-up
		boolean asDialog = getIntent().getExtras().getBoolean(Constants.POPUP_AS_DIALOG_KEY);

		// Getting random phrase id number to send as parameter to fragments.
		int randomPhraseId = Phrases.GetRandomPhraseId(getBaseContext());
        
		// Adding number to arguments object.
        Bundle args = new Bundle(); 
        args.putInt(Constants.PHRASE_ID_KEY, randomPhraseId);
		

		if (asDialog)
		{
			DialogPopupFragment dialogPopup = new DialogPopupFragment();
			dialogPopup.setArguments(args); // Adding arguments
			dialogPopup.show(getSupportFragmentManager(), "DialogPopupFragment");
		}
		else
		{
			setContentView(R.layout.main_container);
			
	        if (findViewById(R.id.fragment_container) != null) 
	        {
	            PopupFragment popup = new PopupFragment();
	            popup.setArguments(args); // Adding arguments
	            getSupportFragmentManager().beginTransaction().add(R.id.fragment_container, popup).commit();
	        }
		}

	}

	// Fragment selection
	public void InflateFragment(Fragment fragment)
	{
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();

        // Replace whatever is in the fragment_container view with this fragment,
        // and add the transaction to the back stack so the user can navigate back
        transaction.replace(R.id.fragment_container, fragment);
        transaction.addToBackStack(null);

        // Commit the transaction
        transaction.commit();
	}
}
